<?php

include("../pChart/pData.class.php");
include("../pChart/pChart.class.php");

header("Content-type: image/png");



$json =  htmlspecialchars_decode($_REQUEST['json']);
$dati = json_decode($json,true);

$chiavi = array();
$valori = array();

foreach ($dati as $k => $v) {
	array_push($chiavi, $k);
	array_push($valori,$v);
}


// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint($valori,"Serie1");
$DataSet->AddPoint($chiavi,"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");

// Initialise the graph
$Test = new pChart(500,200);
$Test->setFontProperties("../resources/FreeSerif.ttf",8);
$Test->drawFilledRoundedRectangle(7,7,493,193,5,240,240,240);
$Test->drawRoundedRectangle(5,5,495,195,5,230,230,230);

// Draw the pie chart
$Test->AntialiasQuality = 0;
$Test->setShadowProperties(2,2,200,200,200);
$Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,60,PIE_PERCENTAGE,8);
$Test->clearShadow();

$Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);

$Test->Stroke();
?>